﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using 开单.Model.基础;
using System.Data;
using System.Data.OleDb;
using winform;

namespace 开单
{
   public class YgxxDao
    {
        YgxxEntity ygxxEntity = new YgxxEntity();
        DataTable dt = new DataTable();
        /// <summary>
        /// 添加员工
        /// </summary>
        /// <param name="YgxxEntity">员工实体类</param>
        public void AddYgxx(YgxxEntity ygxxEntity)
        {
            string sql = string.Empty;
            OleDbParameter[] parameters = {
                     new OleDbParameter("@yg_name", ygxxEntity.yg_name),
                     new OleDbParameter("@yg_jp", ygxxEntity.yg_jp)};

            sql = "insert into jc_ygxx(yg_name,yg_jp) values " +
                    "(@yg_name,@yg_jp)";

            DbHelperOleDb.ExecuteSql(sql, parameters);
        }

        /// <summary>
        /// 删除员工
        /// </summary>
        /// <param name="YgxxEntity">员工实体类</param>
        public void DelYgxx(object yg_code)
        {
            string sql = string.Empty;
            OleDbParameter[] parameters = {
                     new OleDbParameter("@yg_code", yg_code)};

            sql = "delete from jc_ygxx where yg_code=@yg_code ";

            DbHelperOleDb.ExecuteSql(sql, parameters);
        }

        /// <summary>
        /// 查询员工信息
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public DataTable GetYgxxDt(string yg_jp)
        {
            yg_jp = "%" + yg_jp + "%";
            OleDbParameter[] paramethers ={
                                             new OleDbParameter("@yg_jp",yg_jp)};
            string sql = "select yg_code as 员工编码,yg_name as 员工名称,yg_jp as 简拼 " +
              " from jc_ygxx where yg_jp like @yg_jp ";
            return DbHelperOleDb.ExecuteWithDataTable(sql, paramethers);
        }

        /// <summary>
        /// 查询员工信息
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public DataTable GetYgxxDtByYgName(string yg_name)
        {
            OleDbParameter[] paramethers ={
                                             new OleDbParameter("@yg_name",yg_name)};
            string sql = "select yg_code as 员工编码,yg_name as 员工名称,yg_jp as 简拼 " +
              " from jc_ygxx where yg_name =@yg_name ";
            return DbHelperOleDb.ExecuteWithDataTable(sql, paramethers);
        }

        /// <summary>
        /// 查询员工信息
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public DataTable GetYgxxDtByYgjp(string yg_jp)
        {
            OleDbParameter[] paramethers ={
                                             new OleDbParameter("@yg_jp",yg_jp)};
            string sql = "select yg_code as 员工编码,yg_name as 员工名称,yg_jp as 简拼 " +
              " from jc_ygxx where yg_jp =@yg_jp ";
            return DbHelperOleDb.ExecuteWithDataTable(sql, paramethers);
        }

        /// <summary>
        /// 更新员工信息
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public void UpdataYgxxByYg_code(YgxxEntity ygxxEntity)
        {
            OleDbParameter[] parameters = {
                     new OleDbParameter("@yg_name", ygxxEntity.yg_name),
                     new OleDbParameter("@yg_jp", ygxxEntity.yg_jp),
                     new OleDbParameter("@yg_code", ygxxEntity.yg_code)};
            string sql = "update jc_ygxx set yg_name=@yg_name,yg_jp=@yg_jp where yg_code=@yg_code ";
            DbHelperOleDb.ExecuteSql(sql, parameters);
        }

        //public int getInfoCount()
        //{
        //    string sql = "select count(*) from jc_ygxx ";
        //    dt = DbHelperOleDb.ExecuteWithDataTable(sql, null);
        //    int i = Convert.ToInt32(dt.Rows[0][0]);
        //    return i;
        //}
    }
}
